{extend name='public/base' /}

{block name="breadcrumb"}
{$crumbs}
{/block}

{block name="body"}
<div class="col-lg-12">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <button class="btn btn-primary btn-xs"><a href="{:url('save_category')}"><i class="fa fa-plus"></i> 添加分类</a> </button>
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>分类名称</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="cate" id="vo"}
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo.level|str_repeat=' -- ', ###}{$vo.name}</td>
                    <td>
                        <button class="btn btn-info btn-xs"><a href="{:url('save_category', ['id' => $vo['id']])}"><i class="fa fa-edit"></i> 编辑</a> </button>
                        <button class="btn btn-danger btn-xs del-cate" data-cate-id="{$vo.id}"><a href="javascript:;"><i class="fa fa-trash"></i> 删除</a> </button>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>
    </div>
</div>
{/block}

{block name="javascript"}
<script>
    $(function () {
        $('.del-cate').click(function () {
            var _this = $(this);
            var id = _this.data('cate-id');
            swal({
                title: "删除分类?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确认",
                closeOnConfirm: false
            }, function () {
                $.get('{:url("article/del_cate")}', {id, id}, function (msg) {
                    if (msg.code != 200) {
                        swal({
                            title: msg.msg,
                            type: "error"
                        });
                    } else {
                        swal({
                            title: msg.msg,
                            type: "success"
                        });
                        _this.parents('tr').fadeOut("slow", function () {
                            $(this).remove();
                        });
                    }
                }, 'json');
            });
        });
    });
</script>
{/block}